package org.watson.hacker.Impl;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class hackerPort extends HttpServlet {
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		      throws ServletException, IOException {
		     HttpSession session = request.getSession();
		     
		     String nameSpace = "http://Hacker.Watson.com/";  
		     String methodName = "getInfo";  
		     String endPoint = "http://localhost:8080/AndroidServer/DataServiceImplService";  
		     String soapAction = "http://Hacker.Watson.com/getInfo";  
	  
		     SoapObject requestSoap = new SoapObject(nameSpace, methodName);  
		     requestSoap.addProperty("arg0", null==request.getParameter("pay")?"1":"1");  
	  
		     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);  
	  
	        //envelope.dotNet = true;  
		     envelope.setOutputSoapObject(requestSoap);  
	  
		     HttpTransportSE transport = new HttpTransportSE(endPoint);  
		     try {
		    	 transport.call(soapAction, envelope);       } catch (Exception e) {  
		    	 e.printStackTrace();  
		     }  
	  
		     SoapObject object = (SoapObject) envelope.bodyIn;  
		     String jsonData = object.getProperty(0).toString();
		     
		     response.setContentType("application/json;utf-8");
		     PrintWriter writer = response.getWriter();
		     writer.write(jsonData);
		     return;
		}

		public void doPost(HttpServletRequest request, HttpServletResponse response)
		      throws ServletException, IOException {

		     doGet(request, response);
		}

}
